import { _decorator, Button, Label, Tween, tween, UITransform } from 'cc';
import { BasePopUp } from '../../../frame/component/ui.pop-up';
import Config from '../../manager/config.manager';
import GameAssets from '../../manager/game.assets';
import type { Popup } from '../page/popup';
const { ccclass, property } = _decorator;

@ccclass('Defeat')
export class Defeat extends BasePopUp<typeof Popup, null> {
	protected default_return: null;

	private lbl_round: Label;
	private lbl_symbol: Label;
	private ui_light: UITransform;

	protected initAfterOnLoad(){
		this.lbl_round = this.node.getChildByName('lbl-round').getComponent(Label);
		this.lbl_symbol = this.node.getChildByName('lbl-symbol').getComponent(Label);
		this.ui_light = this.node.getChildByName('light').getComponent(UITransform);
		this.renderLocalUI();
	}

	protected _click_event_: { [name: string]: (this: Defeat, button: Button) => void; } = {
		close(btn){
			btn.interactable = false;
			BasePopUp.jelly_leave(this.node).then(()=>{
				Tween.stopAllByTarget(this.ui_light.node);
				this.ui_light.node.angle = 0;
				this.close(null);
				btn.interactable = true;
			});
		}
	}

	public onShow(round: number, symbol: number){
		this.lbl_round.string = GameAssets.getLangText(19, round);
		this.lbl_symbol.string = Config.symbolString(symbol);
		tween(this.ui_light.node)
		.set({angle: 0}) .to(5, {angle: -360}) .union()
		.repeatForever() .start();
		BasePopUp.jelly_enter(this.node);
	}

	private renderLocalUI(){
		(<const>[
			['head', 36],
			['desc', 37],
			['close', 38]
		]).forEach(([name, idx])=>this.node.getChildByName('lbl-'+name).getComponent(Label).string = GameAssets.getLangText(idx));

		mtec.cc.skinPeeler(this.node.getChildByName('icon'), GameAssets.getCounTexture(4), {height: true});
	}
}

